package grobit.torrent

import grobit.bencode.Bencoder
import org.springframework.core.io.ClassPathResource

class MetaInfoTest extends GroovyTestCase {

    void testCreateMetaInfoFromFile() {
        def input = new BufferedInputStream(new ClassPathResource('pi.torrent').getInputStream())
        MetaInfo metaInfo = MetaInfo.createFromMap(Bencoder.decodeNext(input))
        input.close()

        assert metaInfo.announce == 'http://downloads.raspberrypi.org:6969/announce'
        assert metaInfo.announceList == []
        assert metaInfo.creationDate?.getTime() == 1360406114000
        assert metaInfo.comment == null
        assert metaInfo.createdBy == 'Transmission/2.76 (13786)'
        assert metaInfo.encoding == 'UTF-8'
        assert metaInfo.pieceLength == 262144
        assert metaInfo.isPrivate == 0
        assert metaInfo.directory == '.'

        assert metaInfo.files.size() == 1
        assert metaInfo.files[0].length == 493587826
        assert metaInfo.files[0].path == '2013-02-09-wheezy-raspbian.zip'
        assert metaInfo.files[0].md5sum == null

        assert metaInfo.totalSize == metaInfo.files[0].length
    }
}
